<template>
	<view class="compose">
		<Navbar>合成</Navbar>
		<image :src="`${baseImageUrl}/home/h3.png`" class="header"></image>
		<view class="tabs">
			<view class="item" :class="active==item.key?'active':''" v-for="item in scroll"
				@click="changeActive(item.key)">
				{{item.title}}
			</view>
		</view>
		<scroll-view scroll-y class="scroll_view" @scrolltolower="loadmore">
			<view class="item" v-for="item in list">
				<image :src="item.cover" class="cover"></image>
				<view class="item_view">
					<view class="name">{{item.name}}</view>
					<view class="time">
						<view>开始时间:{{item.start_date}}</view>
						<view>结束时间:{{item.end_date}}</view>
					</view>
					<view class="btn">
						<view v-if="item.status==1" @click="router(`/pages/home/compose_deta?id=${item.id}`)">立即参与
						</view>
						<view class="not" v-else>已结束</view>
					</view>
				</view>
			</view>
			<u-loadmore :status="loadmore_status" :color="$store.state.loadmoreColor"
				:lineColor="$store.state.loadmoreColor" line @loadmore="loadmore" />
		</scroll-view>
	</view>
</template>

<script>
	import {
		composeLists
	} from '@/request/api.js';
	export default {
		data() {
			return {
				active: "",
				scroll: [],
				list: []
			}
		},
		async onLoad() {
			let res = await composeLists({
				page: this.page,
				limit: this.limit,
				product_type: this.active
			});
			let list = this.scroll = res.class;
			this.active = list.length ? list[0].key : "";

			this.getList();
		},
		methods: {
			async getList() {
				let {
					list
				} = await composeLists({
					page: this.page,
					limit: this.limit,
					type: this.active
				});
				this.last_page = list.last_page;
				list = list.list;
				this.list = this.page == 1 ? list : [...this.list, ...list];
				this.loadmore_status = this.last_page == this.page ? 'nomore' : 'loadmore';
			},
			loadmore() {
				if (this.page < this.last_page) {
					this.page++;
					this.getList();
				}
			},
			changeActive(value) {
				this.active = value;
				this.page = 1;
				this.list = [];
				this.getList()
			}
		}
	}
</script>

<style scoped lang="scss">
	.compose {
		height: 100vh;
		background: #29170D;
		overflow: hidden;

		.header {
			width: 100%;
			height: 240rpx;
		}

		.tabs {
			width: 710rpx;
			height: 100rpx;
			margin: 0 auto;
			padding: 0 15rpx;
			box-sizing: border-box;
			background-color: rgba(31, 11, 5, 0.6);
			display: flex;
			justify-content: space-between;
			align-items: center;

			.item {
				width: 180rpx;
				height: 80rpx;
				line-height: 80rpx;
				text-align: center;
				color: #FFFFFF;
				font-size: 36rpx;
				font-weight: 400;
				font-family: LiSu;

				&.active {
					color: #494338;
					background: url(#{$baseImageUrl}/common/active.png) no-repeat;
					background-size: 100% 100%;
				}
			}
		}

		.scroll_view {
			height: calc(100vh - #{$navbarHeight} - 340rpx);
			padding: 24rpx 30rpx;
			box-sizing: border-box;

			.item {
				height: 252rpx;
				margin-bottom: 20rpx;
				padding: 16rpx 18rpx;
				box-sizing: border-box;
				background: url(#{$baseImageUrl}/bg/690_252.png) no-repeat;
				background-size: 100% 100%;
				display: flex;

				.cover {
					width: 220rpx;
					height: 100%;
				}

				.item_view {
					flex: 1;
					padding: 10rpx 0 0 18rpx;
					box-sizing: border-box;
					overflow: hidden;
					display: flex;
					flex-direction: column;
					justify-content: space-between;

					.name {
						color: #494338;
						font-size: 42rpx;
						font-weight: 400;
						font-family: LiSu;
					}

					.time {
						view {
							color: #494338;
							font-size: 24rpx;
							font-weight: 400;
							font-family: SimSun;
							margin-bottom: 10rpx;

							&:last-child {
								margin-bottom: 0;
							}
						}
					}

					.btn {
						display: flex;
						justify-content: flex-end;

						view {
							width: 204rpx;
							height: 74rpx;
							line-height: 74rpx;
							text-align: center;
							color: #FFFFFF;
							font-size: 30rpx;
							font-weight: 400;
							font-family: SimSun;
							background: url(#{$baseImageUrl}/common/btn.png) no-repeat;
							background-size: 100% 100%;

							&.not {
								background: url(#{$baseImageUrl}/common/btn2.png) no-repeat;
								background-size: 100% 100%;
							}
						}
					}
				}
			}
		}
	}
</style>